import React, { Component } from 'react';
import { Modal, Button, message, Form, Row, Col, Input, Checkbox, Icon, InputNumber, Popconfirm, Switch } from 'antd';

const FormItem = Form.Item;
import equal from 'deep-equal';
import { WeaDialog, WeaRightMenu, WeaInput, WeaSearchGroup, WeaTools, WeaFormItem } from 'ecCom';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

class RemindSetModal extends Component {
    static contextTypes = {
      antLocale: React.PropTypes.object,
    }
    constructor(props) {
      super(props);
      this.state = {
        contactVisible: false,
        showGroup: true,
        isremind: props.remindInfo.isRemind || '1',
        before: props.remindInfo.before || 1,
      };
      this.doAdd = this.doAdd.bind(this);
    }

    componentWillReceiveProps(nextProps, nextState) {
      const { remindInfo = {} } = this.props;
      if (!equal(nextProps.remindInfo, this.props.remindInfo)) {
        this.setState({
          isremind: nextProps.remindInfo.isRemind,
          before: nextProps.remindInfo.before,
        });
      }
    }
    render() {
      const { contactVisible, showGroup, isremind, before } = this.state;
      const { customerId, remindInfo } = this.props;
      const formItemLayout = {
        labelCol: { span: 4 },
        wrapperCol: { span: 18 },
      };
      return (
        <div>
          <WeaDialog
            ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@aoeqmm`}
            style={{ width: 600, height: 200 }}
            visible={contactVisible}
            title={getLabel(84369, '联系提醒设置')}
            icon="icon-coms-crm"
            iconBgcolor="#96358a"
            buttons={this.getRemindButtons()}
            onCancel={() => this.setContactVisible(false)}
          >
            <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@avib83`} needTigger title={getLabel(33396, '设置项')} showGroup >
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5sfh9k`}
                {...formItemLayout}
                label={getLabel(18095, '启用')}
              >
                <Switch ecId={`${this && this.props && this.props.ecId || ''}_Switch@o2n7gr`} checked={isremind == '0'} onChange={this.onSwitchChange} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ai29ok`}
                {...formItemLayout}
                label={getLabel(34219, '超过')}
              >
                <InputNumber ecId={`${this && this.props && this.props.ecId || ''}_InputNumber@aw66bs`} min={1} max={9999999} value={Number(before)} onChange={this.onOutChange} />
                <span>{getLabel(34221, '天未进行客户联系时自动提醒')}</span>
              </WeaFormItem>
            </WeaSearchGroup>
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@965786`} style={{ display: 'none' }} title={getLabel(1421, '新增')} size="small" onClick={this.doAdd}><Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@y9jjav`} type="plus" /></Button>
          </WeaDialog>
        </div>
      );
    }
    doAdd() {

    }

    setContactVisible = (visible) => {
      this.setState({ contactVisible: visible });
    }
    getButtons() {
      const btn = [];
      btn.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@d5ns8q@close`} onClick={() => this.setVisible(false)}>{getLabel(309, '关闭')}</Button>);
      return btn;
    }

    getRemindButtons() {
      const btn = [];
      btn.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zufx04@save`} type="primary" onClick={this.saveRemindSetting.bind(this)}>{getLabel(86, '保存')}</Button>);
      btn.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@4771ib@close`} onClick={() => this.setContactVisible(false)}>{getLabel(309, '关闭')}</Button>);

      return btn;
    }
    onSwitchChange=(checked) => {
      this.setState({ isremind: checked ? '0' : '1' });
    }
    onOutChange=(value) => {
      this.setState({ before: value });
    }
    saveRemindSetting() {
      const { before, isremind } = this.state;
      const { customerId } = this.props;
      { typeof this.props.saveRemindSetting === 'function' && this.props.saveRemindSetting({ customerId, before, isremind }); }
      this.setContactVisible(false);
    }
}

export default RemindSetModal;
